/*
    Copyright (C) 2025 mio <stigma@disroot.org>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/
#include "aster_slider.h"

AsterSlider::AsterSlider(TQWidget *parent)
    : TQSlider(parent)
    , m_isHeld(false)
{
    setTracking(false);
}

void AsterSlider::setValue(int value)
{
    TQSlider::setValue(value);

    if (isHeld()) {
        emit sliderMoved(value);
    }
}

void AsterSlider::mouseMoveEvent(TQMouseEvent *event)
{
    if (isHeld()) {
        setValue(TQRangeControl::valueFromPosition(event->x(), width()));
    }
    TQSlider::mouseMoveEvent(event);
}


void AsterSlider::mousePressEvent(TQMouseEvent *event)
{
    if (event->button() != TQMouseEvent::LeftButton) {
        TQSlider::mousePressEvent(event);
        return;
    }

    m_isHeld = true;
    setValue(TQRangeControl::valueFromPosition(event->x(), width()));
}

void AsterSlider::mouseReleaseEvent(TQMouseEvent *event)
{
    m_isHeld = false;
    TQSlider::mouseReleaseEvent(event);
}

#include "aster_slider.moc"



